<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <h3></h3>


  <!-- 利用iframe完成跨域 -->
  <iframe src="http://localhost:4000" frameborder="1" style="display: none;" onload="load(this)"></iframe>

  <script>
    function load(obj) {
      obj.contentWindow.postMessage('我是一个消息，你发打印', 'http://localhost:4000')
    }

    window.onmessage = e => {
      document.querySelector('h3').innerHTML = e.data
    }

  </script>

</body>

</html>